/**
 * Created by Administrator on 2017/9/11.
 */
$(document).ready(function () {
    
    
    var redTpl=$('#red-list-template').html();

    var redCmp=Handlebars.compile(redTpl);

    $.ajax({
        url:C.interface.redList,
        type:'get',
        dataType:'json',
        data:{
            token:C.token
        },
        success:function (response) {
            if (response.result === 'success'){
                var data=response.data;
                console.log(data);
                $('#red-list-box').html(redCmp(data));

                $('.aui-swipe-btn').bind('click',deleteRed)

            }else if (response.result === 'login'){
                alert('登录已过期，请重新登录');
                againLogin();

            }else {
                alert(response.errorMsg);
            }
        }
    });

    function deleteRed(event) {
        event.preventDefault();

        var that=$(this);

        dialog.confirm({
            title:"确定要删除吗",
            content:"",
            ok:function () {

                var id = that.parents('.aui-list-item').data('id');

                $.ajax({
                    url:C.interface.redDel,
                    type:'get',
                    dataType:'json',
                    data:{
                        token:C.token,
                        id:id
                    },
                    success:function (response) {
                        if (response.result === 'success'){

                            dialog.tusiSuccess('删除成功');
                            that.parents('.aui-list-item').remove();

                        }else if (response.result === 'login'){
                            alert('请重新登录');
                        }else {
                            alert(response.errorMsg);
                        }
                    }
                })

            },
            cancel: function () {

            }
        });



    }


});